package com.itheima.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.mapper.ClazzMapper;
import com.itheima.pojo.Clazz;
import com.itheima.pojo.PageBean;
import com.itheima.service.ClazzService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.List;

@Service
public class ClazzServiceImpl implements ClazzService {

    @Autowired
    ClazzMapper clazzMapper;

    @Override
    public PageBean pageString(Integer page, Integer pageSize, String name, LocalDate begin, LocalDate end) {
        PageHelper.startPage(page,pageSize);
        Page<Clazz> p=(Page<Clazz>) clazzMapper.list(name,begin,end);
        return new PageBean(p.getResult(),p.getTotal());
    }

    //删除班级
    @Override
    public void deleteById(Integer id) {
        clazzMapper.deleteById(id);
    }

    //添加班级
    @Override
    public void insert(Clazz clazz) {
        clazz.setCreateTime(LocalDateTime.now());
        clazz.setUpdateTime(LocalDateTime.now());
        clazzMapper.insert(clazz);
    }

    //根据ID查询
    @Override
    public Clazz getById(Integer id) {
        return clazzMapper.getById(id);
    }
    //修改班级
    @Override
    public void updateById(Clazz clazz) {
        clazz.setUpdateTime(LocalDateTime.now());
        clazzMapper.updateById(clazz);
    }

    //查询所有班级
    @Override
    public List<Clazz> list() {
        return clazzMapper.listAll();
    }
}
